package com.example.es.controller;

import com.example.es.service.ElasticSearchService;
import com.example.es.vo.UserInfo;
import com.example.es.vo.Video;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.IOException;
import java.util.List;
import java.util.Map;

/**
 * ProjectName es
 *
 * @author xieyucan
 * <br>CreateDate 2022/12/29 10:29
 */
@RestController
@RequestMapping("/es")
public class EsController {

    @Resource
    private ElasticSearchService elasticSearchService;

    @PostMapping("/addUserInfo")
    public void addUserInfo(@RequestBody UserInfo userInfo){
        elasticSearchService.addUserInfo(userInfo);
    }


    @PostMapping("/addVideo")
    public void addVideo(@RequestBody Video video)
    {
        elasticSearchService.addVideo(video);
    }

    @GetMapping("/getVideos")
    public Video getVideos(String keyword)
    {
        return elasticSearchService.getVideos(keyword);
    }

    @GetMapping("/getContents")
    public List<Map<String,Object>> getContents(String keyword,
                                                Integer pageNo,
                                                Integer pageSize) throws IOException {
        return elasticSearchService.getContents(keyword, pageNo, pageSize);
    }
}
